package com.xiaoyu.base.entity;

import androidx.room.Entity;
import androidx.room.Index;
import androidx.room.PrimaryKey;
import androidx.annotation.NonNull;
import android.text.TextUtils;
import in.srain.cube.request.JsonData;

import java.util.Objects;

@Entity(tableName = "sticker", indices = {@Index(value = {"uid", "stickerId"}, unique = true)})
public class StickerEntity {

    @PrimaryKey
    private long stickerId;
    @NonNull
    private String uid;
    private long ord;
    @NonNull
    private String url;
    private String desc;

    public StickerEntity() {
        uid = "";
        stickerId = 0;
        ord = 0;
        url = "";
        desc = "";
    }

    public StickerEntity(JsonData jsonData) {
        this.uid = jsonData.optString("uid");
        this.stickerId = jsonData.optLong("sticker_id");
        this.ord = jsonData.optLong("ord");
        this.url = jsonData.optString("url");
        this.desc = jsonData.optString("desc");
    }

    @NonNull
    public String getUid() {
        return uid;
    }

    public void setUid(@NonNull String uid) {
        this.uid = uid;
    }

    public long getStickerId() {
        return stickerId;
    }

    public void setStickerId(long stickerId) {
        this.stickerId = stickerId;
    }

    public long getOrd() {
        return ord;
    }

    public void setOrd(long ord) {
        this.ord = ord;
    }

    @NonNull
    public String getUrl() {
        return url;
    }

    public void setUrl(@NonNull String url) {
        this.url = url;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof StickerEntity)) {
            return false;
        }
        StickerEntity that = (StickerEntity) o;
        if (stickerId != that.stickerId) {
            return false;
        }
        if (ord != that.ord) {
            return false;
        }
        if (!TextUtils.equals(uid, that.uid)) {
            return false;
        }
        if (!TextUtils.equals(url, that.url)) {
            return false;
        }
        if (!TextUtils.equals(desc, that.desc)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        return Objects.hash(stickerId, uid);
    }

    @NonNull
    @Override
    public String toString() {
        return "StickerEntity{" +
                "stickerId=" + stickerId +
                ", uid='" + uid + '\'' +
                ", ord=" + ord +
                ", url='" + url + '\'' +
                ", desc='" + desc + '\'' +
                '}';
    }
}
